home *** CD-ROM | disk | FTP | other *** search
- package MemoryGame;
-
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.util.Random;
- import java.util.Timer;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- import javax.microedition.rms.RecordStore;
-
- public class MemoryCanvas extends Canvas implements Runnable {
- private Display display;
- private Display BackBuff;
- // $FF: renamed from: h int
- private int field_0 = 0;
- // $FF: renamed from: w int
- private int field_1 = 0;
- private Image[] Card;
- public int[] XPos;
- public int[] YPos;
- public int[] CardId;
- public boolean[] CardVis;
- public boolean[] CardCleard;
- long time1;
- long time2;
- long wait1;
- long wait2;
- long Level;
- long RestTime;
- boolean ShowGetTimeBonus;
- boolean ShowPerfect;
- boolean ShowHighScore;
- boolean StartGame;
- boolean EndGame;
- boolean Begin;
- boolean ShowTitel;
- boolean NoPaintBorad;
- boolean RoundClear;
- boolean Perfect;
- boolean BreakWhile;
- boolean GetTimeBonusActive;
- boolean CanBreak;
- boolean NoCheckTwice;
- int score;
- Font font;
- Timer timer = new Timer();
- Thread thread;
- public String[] names = new String[]{"Mem", "Mem", "Mem", "Mem"};
- public int[] values = new int[]{2000, 1700, 1500, 100};
- public static int TitX1;
- public static int TitX2;
- public static int TitX3;
- public static int TitX4;
- public static int TitX5;
- public static int TitY1;
- public static int TitY2;
- public static int TitY3;
- public static int TitY4;
- public static int TitY5;
- private Image _buffer;
-
- public MemoryCanvas(Display var1) {
- this.GetHighScores();
- this.InitGraphics();
- this.SetCardPos();
- this.display = var1;
- this.thread = new Thread(this);
- this.thread.start();
- }
-
- protected void keyPressed(int var1) {
- if (this.CardsVisible() < 3) {
- if (this.CardsVisible() == 2) {
- this.NoCheckTwice = true;
- this.CheckForGoed();
-
- for(int var2 = 0; var2 < 13; ++var2) {
- this.CardVis[var2] = false;
- }
-
- ((Canvas)this).repaint();
- Thread.yield();
- this.NoCheckTwice = true;
- }
-
- if (this.CanBreak) {
- this.BreakWhile = true;
- }
-
- if (this.ShowGetTimeBonus || this.ShowPerfect) {
- var1 = 0;
- }
-
- if (this.StartGame) {
- if (var1 == 49 & !this.CardVis[1] & !this.CardCleard[1]) {
- this.CardVis[1] = true;
- }
-
- if (var1 == 50 & !this.CardVis[2] & !this.CardCleard[2]) {
- this.CardVis[2] = true;
- }
-
- if (var1 == 51 & !this.CardVis[3] & !this.CardCleard[3]) {
- this.CardVis[3] = true;
- }
-
- if (var1 == 52 & !this.CardVis[4] & !this.CardCleard[4]) {
- this.CardVis[4] = true;
- }
-
- if (var1 == 53 & !this.CardVis[5] & !this.CardCleard[5]) {
- this.CardVis[5] = true;
- this.StartGame = true;
- }
-
- if (var1 == 54 & !this.CardVis[6] & !this.CardCleard[6]) {
- this.CardVis[6] = true;
- }
-
- if (var1 == 55 & !this.CardVis[7] & !this.CardCleard[7]) {
- this.CardVis[7] = true;
- }
-
- if (var1 == 56 & !this.CardVis[8] & !this.CardCleard[8]) {
- this.CardVis[8] = true;
- }
-
- if (var1 == 57 & !this.CardVis[9] & !this.CardCleard[9]) {
- this.CardVis[9] = true;
- }
-
- if (var1 == 42 & !this.CardVis[10] & !this.CardCleard[10]) {
- this.CardVis[10] = true;
- }
-
- if (var1 == 48 & !this.CardVis[11] & !this.CardCleard[11]) {
- this.CardVis[11] = true;
- }
-
- if (var1 == 35 & !this.CardVis[12] & !this.CardCleard[12]) {
- this.CardVis[12] = true;
- }
- } else if (var1 == 53) {
- this.StartGame = true;
- }
- }
-
- ((Canvas)this).repaint();
- }
-
- protected void keyRepeated(int var1) {
- }
-
- protected void keyReleased(int var1) {
- }
-
- protected void pointerPressed(int var1, int var2) {
- }
-
- protected void pointerReleased(int var1, int var2) {
- }
-
- protected void pointerDragged(int var1, int var2) {
- }
-
- public void run() {
- this.Begin = true;
- this.StartGame = false;
- this.ShowTitel = false;
-
- for(this.EndGame = true; this.Begin; this.StartGame = false) {
- TitX1 = 100;
- TitY2 = 80;
- TitX3 = -100;
- TitX4 = 100;
- int var1 = 850;
- int var2 = 50000;
- this.Level = 1L;
- this.score = 0;
- this.EndGame = true;
- this.NoPaintBorad = true;
- this.ShowTitel = true;
- ((Canvas)this).repaint();
- Thread.yield();
- this.CanBreak = true;
- this.wait(10000);
- this.ShowTitel = false;
- ((Canvas)this).repaint();
- Thread.yield();
- this.ShowHighScore = true;
- ((Canvas)this).repaint();
- Thread.yield();
- this.CanBreak = true;
- this.wait(7000);
- this.ShowHighScore = false;
- ((Canvas)this).repaint();
- Thread.yield();
- if (this.StartGame) {
- this.EndGame = false;
- }
-
- while(!this.EndGame) {
- this.RestTime = (long)(var2 / 1000);
- this.NoPaintBorad = false;
- this.ResetAllCards();
- this.MixCards();
- this.wait(2000);
- this.ShowCards(var1);
- this.ShowBackCards();
- this.time1 = System.currentTimeMillis();
- this.time2 = System.currentTimeMillis() + (long)var2;
- this.Perfect = true;
- this.RoundClear = false;
-
- while(!this.RoundClear) {
- this.time1 = System.currentTimeMillis();
- this.RestTime = (this.time2 - this.time1) / 1000L;
- if (this.CardsVisible() >= 2) {
- this.wait(700);
- if (this.CardsVisible() == 2) {
- this.NoCheckTwice = false;
- }
-
- if (!this.NoCheckTwice) {
- this.CheckForGoed();
-
- for(int var3 = 0; var3 < 13; ++var3) {
- this.CardVis[var3] = false;
- }
- }
- }
-
- ((Canvas)this).repaint();
- Thread.yield();
- if (this.CheckEndRound()) {
- if (var1 > 200) {
- var1 -= 40;
- }
-
- if (var2 > 15000) {
- var2 -= 3000;
- }
-
- ++this.Level;
-
- for(int var10 = 1; var10 < 13; ++var10) {
- this.CardCleard[var10] = false;
- }
-
- if (this.Perfect) {
- this.ShowPerfect = true;
- this.score += 100;
- ((Canvas)this).repaint();
- Thread.yield();
-
- try {
- Thread.sleep(1000L);
- } catch (Exception var9) {
- }
-
- this.ShowPerfect = false;
- }
-
- try {
- Thread.sleep(500L);
- } catch (Exception var8) {
- }
-
- this.ShowGetTimeBonus = true;
-
- try {
- Thread.sleep(1000L);
- } catch (Exception var7) {
- }
-
- ((Canvas)this).repaint();
- Thread.yield();
- this.wait(900);
-
- while(this.RestTime > 0L) {
- --this.RestTime;
- this.score += 4;
- ((Canvas)this).repaint();
-
- try {
- Thread.sleep(5L);
- } catch (Exception var6) {
- }
- }
-
- try {
- Thread.sleep(1000L);
- } catch (Exception var5) {
- }
-
- this.ShowGetTimeBonus = false;
- this.RoundClear = true;
- }
-
- if (this.RestTime < 0L) {
- this.RoundClear = true;
- this.EndGame = true;
- }
- }
- }
-
- if (this.isHighScore(this.score)) {
- MemoryMIDlet.HiScoreOk = false;
- MemoryMIDlet.enterHighScore();
-
- while(!MemoryMIDlet.HiScoreOk) {
- Thread.yield();
- }
-
- String var11 = MemoryMIDlet._scoreField.getString();
- this.addHighScore(this.score, var11);
- this.NoPaintBorad = true;
- this.ShowHighScore = true;
- ((Canvas)this).repaint();
- Thread.yield();
- this.CanBreak = true;
- this.wait(7000);
- this.ShowHighScore = false;
- ((Canvas)this).repaint();
- Thread.yield();
- }
- }
-
- }
-
- public void wait(int var1) {
- this.BreakWhile = false;
- this.wait1 = System.currentTimeMillis();
- this.wait2 = System.currentTimeMillis() + (long)var1;
-
- while(this.wait1 < this.wait2 && !this.BreakWhile) {
- this.wait1 = System.currentTimeMillis();
- ((Canvas)this).repaint();
- Thread.yield();
- }
-
- this.CanBreak = false;
- }
-
- public void ResetAllCards() {
- for(int var1 = 0; var1 < 13; ++var1) {
- this.CardCleard[var1] = false;
- this.CardVis[var1] = false;
- }
-
- }
-
- public boolean CheckEndRound() {
- boolean var1 = true;
-
- for(int var2 = 1; var2 < 13; ++var2) {
- if (!this.CardCleard[var2]) {
- var1 = false;
- }
- }
-
- return var1;
- }
-
- public void CheckForGoed() {
- int var1 = 0;
- int var2 = 0;
-
- for(int var3 = 1; var3 < 13; ++var3) {
- if (this.CardVis[var3]) {
- if (var1 == 0) {
- var1 = var3;
- } else {
- var2 = var3;
- }
- }
- }
-
- if (var1 > 0 & var2 > 0) {
- if (this.CardId[var1] == this.CardId[var2]) {
- this.CardCleard[var1] = true;
- this.CardCleard[var2] = true;
- this.score += 10;
- } else {
- this.Perfect = false;
- }
- }
-
- }
-
- public int CardsVisible() {
- int var1 = 0;
-
- for(int var2 = 1; var2 < 13; ++var2) {
- if (this.CardVis[var2]) {
- ++var1;
- }
- }
-
- return var1;
- }
-
- public void paint(Graphics var1) {
- Graphics var2 = this._buffer.getGraphics();
- var2.setColor(16777215);
- var2.fillRect(0, 0, this.field_1, this.field_0);
- var2.setColor(0);
- Font.getFont(0, 1, 8);
- var2.setFont(this.font);
- if (this.ShowHighScore) {
- this.DisplayHighScore(var2);
- }
-
- if (this.ShowTitel) {
- this.DisplayTitle(var2);
- }
-
- if (!this.ShowHighScore && !this.ShowTitel && !this.NoPaintBorad) {
- this.DrawLevelBackGround(var2);
- this.PaintCards(var2);
- var2.drawString("T:" + this.RestTime, 62, 10, 20);
- var2.drawString("L:" + this.Level, 62, 20, 20);
- var2.drawString("S:" + this.score, 62, 40, 20);
- }
-
- if (this.ShowGetTimeBonus) {
- this.GetTimeBonus(var2, this.RestTime);
- }
-
- if (this.ShowPerfect) {
- this.GetPerfect(var2);
- }
-
- if (this._buffer != null) {
- var1.drawImage(this._buffer, 0, 0, 20);
- }
-
- }
-
- public void GetTimeBonus(Graphics var1, long var2) {
- var1.setColor(16777215);
- var1.fillRect(0, 15, 100, 40);
- var1.setColor(0);
- var1.drawString("Time Bonus", 30, 20, 20);
- var1.drawString("Time " + this.RestTime + " X 4 =", 10, 36, 20);
- var1.drawString("" + this.score, 80, 36, 20);
- }
-
- public void GetPerfect(Graphics var1) {
- var1.setColor(16777215);
- var1.fillRect(0, 15, 100, 40);
- var1.setColor(0);
- var1.drawString(" Perfect", 40, 20, 20);
- var1.drawString("100 Points", 40, 36, 20);
- }
-
- public void ShowCards(int var1) {
- for(int var2 = 1; var2 < 13; ++var2) {
- this.CardVis[var2] = true;
- }
-
- ((Canvas)this).repaint();
- this.CanBreak = true;
- this.wait(var1 * 10);
- }
-
- public void ShowBackCards() {
- for(int var1 = 0; var1 < 13; ++var1) {
- this.CardVis[var1] = false;
- }
-
- ((Canvas)this).repaint();
-
- try {
- Thread.sleep(100L);
- } catch (Exception var3) {
- }
-
- }
-
- public void ShowTimerLine(Graphics var1) {
- }
-
- public void SetCardPos() {
- boolean var1 = false;
- boolean var2 = false;
- int var3 = 0;
- int var4 = 0;
- int var5 = 0;
-
- for(int var7 = 0; var7 < 4; ++var7) {
- for(int var6 = 0; var6 < 3; ++var6) {
- ++var5;
- var4 = 6 + var7 * this.Card[0].getHeight();
- var3 = 6 + var6 * (this.Card[0].getWidth() + 2);
- this.XPos[var5] = var3;
- this.YPos[var5] = var4;
- }
- }
-
- }
-
- public void PaintCards(Graphics var1) {
- for(int var2 = 1; var2 < 13; ++var2) {
- if (!this.CardCleard[var2]) {
- if (this.CardVis[var2]) {
- this.DrawCard(var1, this.Card[this.CardId[var2]], this.XPos[var2], this.YPos[var2]);
- } else {
- this.DrawCard(var1, this.Card[0], this.XPos[var2], this.YPos[var2]);
- }
- }
- }
-
- }
-
- public void DrawCard(Graphics var1, Image var2, int var3, int var4) {
- var1.drawImage(var2, var3, var4, 16 | 4);
- }
-
- public void DrawLevelBackGround(Graphics var1) {
- var1.drawLine(1, 1, this.field_1 - 1, 1);
- var1.drawLine(1, this.field_0 - 1, this.field_1 - 1, this.field_0 - 1);
- var1.drawLine(1, 1, 1, this.field_0 - 1);
- var1.drawLine(this.field_1 - 1, 1, this.field_1 - 1, this.field_0 - 1);
- var1.drawLine(this.field_1 / 2 + 10, 1, this.field_1 / 2 + 10, this.field_0 - 1);
- }
-
- public void InitGraphics() {
- this.field_1 = 100;
- this.field_0 = 74;
- this.XPos = new int[13];
- this.YPos = new int[13];
- this.Card = new Image[13];
- this.CardId = new int[13];
- this.CardVis = new boolean[13];
- this.CardCleard = new boolean[13];
-
- for(int var1 = 0; var1 < 13; ++var1) {
- this.CardVis[var1] = false;
- this.CardCleard[var1] = false;
- }
-
- this._buffer = Image.createImage(this.field_1, this.field_0);
-
- try {
- this.Card[0] = Image.createImage("/MemoryGame/CardBack.png");
- this.Card[1] = Image.createImage("/MemoryGame/Card1.png");
- this.Card[2] = Image.createImage("/MemoryGame/Card2.png");
- this.Card[3] = Image.createImage("/MemoryGame/Card3.png");
- this.Card[4] = Image.createImage("/MemoryGame/Card4.png");
- this.Card[5] = Image.createImage("/MemoryGame/Card5.png");
- this.Card[6] = Image.createImage("/MemoryGame/Card6.png");
- } catch (Exception var3) {
- System.out.print(var3);
- }
-
- }
-
- public int GetRandom(int var1) {
- int var2 = 0;
-
- for(Random var3 = new Random(); var2 < 1; var2 = var3.nextInt() % var1 + 1) {
- }
-
- return var2;
- }
-
- public void MixCards() {
- int[] var4 = new int[13];
-
- for(int var5 = 1; var5 < 13; ++var5) {
- var4[var5] = 0;
- this.CardId[var5] = 0;
- }
-
- for(int var6 = 1; var6 < 7; ++var6) {
- for(int var7 = 1; var7 < 3; ++var7) {
- int var2 = this.GetRandom(12);
-
- while(this.CardId[var2] > 0) {
- var2 = this.GetRandom(12);
- boolean var3 = false;
-
- for(int var8 = 1; var8 < 13; ++var8) {
- if (this.CardId[var8] == 0) {
- var3 = true;
- }
- }
-
- if (!var3) {
- break;
- }
- }
-
- if (this.CardId[var2] == 0) {
- this.CardId[var2] = var6;
- }
- }
- }
-
- }
-
- public boolean isHighScore(int var1) {
- for(int var2 = 0; var2 < this.names.length; ++var2) {
- if (var1 >= this.values[var2]) {
- return true;
- }
- }
-
- return false;
- }
-
- public void DisplayHighScore(Graphics var1) {
- this.DrawLevelBackGround(var1);
- var1.drawString("HighScore", 5, 5, 20);
-
- for(int var2 = 0; var2 < 4; ++var2) {
- var1.drawString(this.names[var2], 3, 20 + 12 * var2, 20);
- var1.drawString("" + this.values[var2], 35, 20 + 12 * var2, 20);
- }
-
- }
-
- public void DisplayTitle(Graphics var1) {
- Font.getFont(0, 1, 16);
- var1.setFont(this.font);
- var1.drawString("Arcade Memory", TitX1, 5, 20);
- Font.getFont(0, 0, 8);
- var1.setFont(this.font);
- var1.drawString("Press '5' to Start", 9, TitY2, 20);
- var1.drawString("Programming by", TitX3, 45, 20);
- var1.drawString("N.Akpolat", TitX4, 60, 20);
- if (TitX1 > 10) {
- TitX1 -= 12;
- } else {
- TitX1 = 10;
- }
-
- if (TitY2 > 25) {
- TitY2 -= 10;
- } else {
- TitY2 = 25;
- }
-
- if (TitX1 <= 11 & TitY2 <= 25) {
- if (TitX3 < 8) {
- TitX3 += 16;
- } else {
- TitX3 = 8;
- }
-
- if (TitX4 > 25) {
- TitX4 -= 16;
- } else {
- TitX4 = 25;
- }
- }
-
- }
-
- public void GetHighScores() {
- RecordStore var1 = null;
-
- try {
- var1 = RecordStore.openRecordStore("HighSscores", true);
- if (var1.getNumRecords() > 0) {
- for(int var2 = 0; var2 < this.names.length; ++var2) {
- byte[] var3 = var1.getRecord(var2 + 1);
- DataInputStream var4 = new DataInputStream(new ByteArrayInputStream(var3, 0, var3.length));
- this.values[var2] = var4.readInt();
- this.names[var2] = var4.readUTF();
- }
- } else {
- for(int var17 = 0; var17 < this.names.length; ++var17) {
- ByteArrayOutputStream var18 = new ByteArrayOutputStream(12);
- DataOutputStream var19 = new DataOutputStream(var18);
- var19.writeInt(this.values[var17]);
- var19.writeUTF(this.names[var17]);
- var19.flush();
- var19.close();
- byte[] var5 = var18.toByteArray();
- var1.addRecord(var5, 0, var5.length);
- }
- }
- } catch (Exception var15) {
- } finally {
- if (var1 != null) {
- try {
- var1.closeRecordStore();
- } catch (Exception var14) {
- }
- }
-
- }
-
- }
-
- public void addHighScore(int var1, String var2) {
- for(int var3 = 0; var3 < this.names.length; ++var3) {
- if (var1 >= this.values[var3]) {
- for(int var4 = this.names.length - 1; var4 > var3; --var4) {
- this.values[var4] = this.values[var4 - 1];
- this.names[var4] = this.names[var4 - 1];
- }
-
- this.values[var3] = var1;
- this.names[var3] = var2;
- RecordStore var5 = null;
-
- try {
- try {
- var5 = RecordStore.openRecordStore("HighSscores", true);
-
- for(int var6 = 0; var6 < this.names.length; ++var6) {
- ByteArrayOutputStream var7 = new ByteArrayOutputStream(12);
- DataOutputStream var8 = new DataOutputStream(var7);
- var8.writeInt(this.values[var6]);
- var8.writeUTF(this.names[var6]);
- var8.flush();
- var8.close();
- byte[] var9 = var7.toByteArray();
- var5.setRecord(var6 + 1, var9, 0, var9.length);
- }
- } catch (Exception var19) {
- }
- break;
- } finally {
- if (var5 != null) {
- try {
- var5.closeRecordStore();
- } catch (Exception var18) {
- }
- }
-
- }
- }
- }
-
- }
- }
-